/*
  展开运算符
    使用方式 ...要展开的东西

  对数组展开

  对对象展开
*/

function getRandomNumbers(length) {
  return Array.from({ length }).reduce((rets, prev) => {
    const num = Math.random();
    rets.push(num);
    return rets;
  }, []);
}

function sum(...args) {
  return args.reduce((cur, prev) => cur + prev);
}

const numbers = getRandomNumbers(10);
console.log(sum(...numbers));

// 数组浅拷贝
const arr1 = [1, 2, 4, 24];
const arr3 = arr1.concat();
const [...arr2] = arr1;
const arr4 = [...arr1];
console.log(arr1, arr3, arr4);

// 对象浅拷贝
const obj = {
  name: "a",
  age: 12,
};
const obj2 = {
  ...obj,
};
const { ...obj4 } = obj;
const obj3 = Object.assign({}, obj);
console.log(obj === obj2, obj === obj3, obj === obj4);
